package com.uff.hmstpa.vision.impl.windows;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.uff.hmstpa.model.ScheduleSystemModel;
import com.uff.hmstpa.model.domain.Healthplan;
import com.uff.hmstpa.vision.command.CreatePatientCommand;

@SuppressWarnings("serial")
public class CreatePatientFrame extends JFrame {

	private JPanel contentPane;
	public JTextField cpfTextField;
	public JTextField patientNameTextField;
	public JComboBox<Healthplan> healthPlanComboBox;

	public CreatePatientFrame(ScheduleSystemModel model) {
		setTitle("Cadastrar Paciente");
		setAlwaysOnTop(true);

		setLocationRelativeTo(null);

		setBounds(100, 100, 450, 231);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblCpf = new JLabel("CPF:");
		lblCpf.setBounds(65, 11, 23, 14);
		contentPane.add(lblCpf);

		JLabel lblNome = new JLabel("Nome:");
		lblNome.setBounds(57, 48, 31, 14);
		contentPane.add(lblNome);

		JLabel lblPlanoDeSade = new JLabel("Plano de Saúde:");
		lblPlanoDeSade.setBounds(10, 87, 78, 14);
		contentPane.add(lblPlanoDeSade);

		cpfTextField = new JTextField();
		cpfTextField.setBounds(98, 8, 326, 20);
		contentPane.add(cpfTextField);
		cpfTextField.setColumns(10);

		patientNameTextField = new JTextField();
		patientNameTextField.setBounds(98, 45, 326, 20);
		contentPane.add(patientNameTextField);
		patientNameTextField.setColumns(10);

		healthPlanComboBox = new JComboBox<Healthplan>();
		healthPlanComboBox.setBounds(98, 84, 326, 20);
		contentPane.add(healthPlanComboBox);

		for(Healthplan hp : model.getHealthplans()) {
			healthPlanComboBox.addItem(hp);
		}

		JButton cadastrarButtom = new JButton(new CreatePatientCommand(cpfTextField, patientNameTextField, healthPlanComboBox));
		cadastrarButtom.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
			}
		});
		cadastrarButtom.setText("Cadastrar");
		cadastrarButtom.setBounds(335, 132, 89, 44);
		contentPane.add(cadastrarButtom);
		
		this.setVisible(false);
	}

}
